package eip.chapter5.sequence.impl;

import org.apache.log4j.Logger;
import org.jibx.runtime.JiBXException;

import eip.chapter5.sequence.BillingService;
import eip.chapter5.sequence.CheckoutBill;
import eip.chapter5.sequence.util.JiBXHelper;

public class BillingServiceImpl implements BillingService {

	private final static Logger logger = Logger.getLogger(BillingServiceImpl.class);
	
	public void processMessage(String message) {
		try {
			CheckoutBill checkoutBill = JiBXHelper.createCheckoutBillFromXML(message);
			generateBilling(checkoutBill);
		} catch (JiBXException e) {
			logger.error("error transforming " + message + " to CheckoutBill", e);
		}
	}
	
	public void generateBilling(CheckoutBill checkoutBill) {
		logger.info("received checkout bill " + checkoutBill);
	}
	
}
